package auth

import "{{ appName }}/lib/event"
import "{{ appName }}/lib/tool"
import "github.com/beego/beego/v2/server/web/context"

func init() {
	//{{ table.name }}Auth()
}

func {{ table.name }}Auth() {
	ez.ListenJoin("{{ table.name }}Auth", func(v interface{},ctx *context.Context) {
		url := ctx.Input.URL()
        		access := true
        		message := "access granted!"
        		switch url {
        		case "/admin/{{ table.name }}/info":
        			access = true
        		case "/admin/{{ table.name }}/scan":
        			access = true
        		case "/admin/{{ table.name }}/list":
        			access = true
        		case "/admin/{{ table.name }}/create":
        			access = true
        		case "/admin/{{ table.name }}/update":
        			access = true
        		case "/admin/{{ table.name }}/edit":
        			access = true
        		case "/admin/{{ table.name }}/copy":
        			access = true
        		case "/admin/{{ table.name }}/delete":
        			access = false
        			message = "access denied!"
        		case "/admin/{{ table.name }}/choice":
        			access = true
        		case "/admin/{{ table.name }}/category":
        			access = true
        		default:
        			if len(ez.MatchAll(url, "/admin/{{ table.name }}/[0-9]"))>0 {
        				//edit
        				access = true
        			}else if  len(ez.MatchAll(url, "/admin/{{ table.name }}/[0-9]/(.+?)"))>0  {
        				access = true
        			}else{
        				access = true
        			}
        		}
        		auth ,_ := v.(*event.AuthEvent)
        		auth.Access = access
        		auth.Message = message
	})
}